package com.aaa.mythread;

public class MyThread6scaleticket extends Thread{

    private Object object = new Object();


    private int ticket=1000;


    @Override
    public  void run() {
        //  业务

        while (true) {
            selltic();
        }
    }

    // java
    // 同步方法
    public synchronized void selltic(){
       // while (true) {
            // synchronized （锁对象）{}
            if (ticket > 0) {
                //  1
                // 1
                System.out.println(Thread.currentThread().getName() + "卖出了一张票，还有" + ticket--);
            }
        //}
    }



    public static void main(String[] args) {
        MyThread6scaleticket myThread4scaleticket = new MyThread6scaleticket();
        Thread thread = new Thread(myThread4scaleticket,"zs");// 4  2
        Thread thread2 = new Thread(myThread4scaleticket,"ls");// 3 3
        Thread thread3 = new Thread(myThread4scaleticket,"ww");// 3 3
        Thread thread4 = new Thread(myThread4scaleticket,"ww1");// 3 3


        thread.start();
        thread2.start();
        thread3.start();
        thread4.start();


    }
}
